<template>
	<view class="list">
		<view class="none" v-if=" !list.length">
			快去创作第一个章节吧~_~
		</view>
		<view class="havelist" v-if="list.length" >
			<view class="chapter-item" v-for="(item,index) in list" :key="index" >
				<view class="top" @tap="href('/pages/post/comps/novchapters/chapterdetail?cid='+item.id + '&nov_id=' + nov_id)">
					<view class="order">
						<text>{{index+1}}.</text>
						<text class="title">第{{item.order}}章</text>
						<text>{{item.title}}</text>
						
					</view>
					<image src="/static/images/user/godetail.png" mode=""></image>
				</view>
				
				<view class="bottom">
					<view class="edit" v-if="action_nov_chapter" @tap.stop="editChapter(item.id)">修改</view>
					<view class="del"  v-if="action_nov_chapter" @tap.stop="delChapter(item.id,index)">删除</view>
				</view>
			</view>
			
		</view>
		<view class="create-area" v-if="action_nov_chapter">
			<view class="create"  @tap="href('/pages/post/comps/novchapters/createchapter?nid='+nov_id )">创建章节</view>
		</view>
	</view>
	
</template>

<script>
	import api from '../../../../common/api.js'
	export default {
		data() {
			return {
				nov_id:'',
				list:[],
				action_nov_chapter:'', 	//是否显示对小说章节进行删除，修改等操作
				isonShow:false
			}
		},
		async onLoad(p) {
			this.nov_id = p.nid
			this.action_nov_chapter = p.action_nov_chapter
			this.list = await api.GetChapters(this.nov_id)
			console.log('列表',this.nov_id);
		},
		onHide() {
			this.isonShow = true
		},
		async onShow() {
			if(this.isonShow) {
				this.list = await api.GetChapters(this.nov_id)
				console.log('onshowwwwww');
			}
		},
		methods:{
			delChapter(id,index) {//删除章节操作
				var that = this
				uni.showModal({
					title:'提示',
					content:'确认删除',
					success:res => {
						if(res.confirm) {
							api.DeleteChapter(id)
							this.list.splice(index,1)
						}
					}
				})
			},
			editChapter(id) {
				uni.navigateTo({
					url:'/pages/post/comps/novchapters/chapterEdit?cid=' + id
				})
			},
			href(url) {//跳转到对应页面
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
.create-area {
	position: fixed;
	height: 150rpx;
	width: 750rpx;
	bottom: 0;
	background-color: #fff;
	border-top: 1rpx solid #F3F6F5;
}
.none {
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	color: #A7AAB5;
}
.havelist {
	padding: 0 30rpx;
	font-size: 30rpx;
}
.chapter-item {
	border-bottom: 2rpx solid #F3F6F5;
}
.top {
	display: flex;
	height: 95rpx;
	justify-content: space-between;
	align-items: center;
	.order {
		font-size: 32rpx;
		.title {
			margin-right: 10rpx;
		}
	}
	image {
		margin-right: 10rpx;
		width: 45rpx;
		height: 45rpx;
	}
}
.bottom {
	display: flex;
	margin-bottom: 10rpx;
	margin-right: 50rpx;
	flex-direction: row-reverse;
	.del,.edit,.wait_check {
		width: 110rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		border-radius: 31rpx;
		font-size: 28rpx;
		color: #6E6E6E;
		margin: 10rpx 10rpx 0;
		border: 1rpx solid #EAEAEA;
	}
	.wait_check {
		color: #DE5A54;
		border: 1rpx solid #E78680;
	}
}
.create {
	position: absolute;
	bottom: 0;
	top: 0;
	width: 600rpx;
	height: 82rpx;
	margin: auto;
	left: 0;
	right: 0;
	text-align: center;
	line-height: 82rpx;
	color: #FFFFFF;
	border-radius:60rpx;
	background-color: #0068FF;
	// position: fixed;
}
</style>
